package com.class04;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

/**
 * @ClassDescription:
 * 编写一个servlet类，用来处理用户请求
 * @JdkVersion: 17
 * @Author: yxy
 * @Created: 2023/11/29 14:21
 */
@WebServlet("/user")
public class HelloServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String parameter = req.getParameter("method");
        if (parameter.equals("add")){
//            req.setCharacterEncoding();
            req.getSession().setAttribute("msg","执行了add方法");
        }else if(parameter.equals("delete")){
            req.getSession().setAttribute("msg","执行了delete方法");
        }
//        业务逻辑
//        视图跳转
        req.getRequestDispatcher("/WEB-INF/jsp/hello.jsp").forward(req,resp);

    }
}

